package com.tentact.servlets;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tentact.service.Chf_DEIdService;
import com.tentact.vo.Chf_DEId;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "Chf_DEId2Servlet", value = "/Chf_DEId2Servlet")
public class Chf_DEId2Servlet extends HttpServlet {
    Chf_DEIdService c_ds=new Chf_DEIdService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Chf_DEId> deid_list=new ArrayList<>();
        if(request.getParameter("departmentId")!=null){
        int   departmentId =Integer.parseInt(request.getParameter("departmentId"));

        deid_list=c_ds.selectEmpById(departmentId);

        ObjectMapper om=new ObjectMapper();
        String deid_string=om.writeValueAsString(deid_list);
        response.setContentType("application/json;charset=utf-8");
        PrintWriter pw=response.getWriter();
        pw.print(deid_string);
        pw.flush();
        pw.close();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
